'''
Python by Marshall
-*- coding: utf-8 -*-
'''
from rest_framework import serializers

from UShop.models import TbGoods, Brand, TbGoodsCategory, Sku


class CategorySerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = TbGoodsCategory
        fields = ('gd_id')

class BrandSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Brand
        fields = ('br_id')

class GoodsSerializer(serializers.HyperlinkedModelSerializer):
    categoryid = serializers.ReadOnlyField(source='spu_category.gd_id')    # 增加外健的字段
    brandid = serializers.ReadOnlyField(source='spu_brand.br_id')  # 添加外健的字段

    class Meta:
        model = TbGoods
        fields = ('spu_id','sup_name','spu_code','spu_comment','categoryid','brandid')


class GSerializer(serializers.ModelSerializer):
    class Meta:
        model = TbGoods
        fields = "__all__"


class SkuSerializer(serializers.ModelSerializer):
    class Meta:
        model = Sku
        fields = "__all__"